<template>
  <el-row type="flex" align="middle" style="height: 40px ;width:100%">
    <el-col>
      <h4 v-if="isRoot">{{ terrData.name }}</h4>
      <span v-else>{{ terrData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <el-col>{{ terrData.manager }}</el-col>
        <el-col>
          <el-dropdown>
            <span class="el-dropdown-link">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDept(terrData)">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="editDepattment(terrData)">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="Deldepartment(terrData.id)">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>

</template>

<script>
import { Deldepartment } from '@/api/department'
export default {
  props: {
    terrData: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean
    }
  },
  methods: {
    async  Deldepartment(id) {
      try {
        await this.$confirm('确定要删除吗？')
        await Deldepartment(id)
        this.$message.success('删除成功')
        this.$emit('Deldepartment')
      } catch (error) {
        console.log(error)
      }
    },
    addDept(data) {
      this.$emit('addDept', data)
    },
    editDepattment(data) {
      this.$emit('editDepattment', data)
    }
  }
}
</script>

<style>

</style>
